//
//  UIViewController+StatusBarStyle.m
//  Epayment
//
//  Created by safiri on 2018/6/29.
//  Copyright © 2018年 safiri. All rights reserved.
//

#import "UIViewController+StatusBarStyle.h"
#import <objc/runtime.h>

@implementation UIViewController (StatusBarStyle)

// MARK: UI Config
/// 配合HUD改变UIStatusBarStyle
- (UIStatusBarStyle)preferredStatusBarStyle {
    return self.statusBarStyleConfig;//childViewControllerForStatusBarStyle 返回nil才起作用
}
- (UIViewController *)childViewControllerForStatusBarStyle {
    return nil;
}

- (void)setStatusBarStyleConfig:(UIStatusBarStyle)statusBarStyleConfig {
    objc_setAssociatedObject(self, @selector(statusBarStyleConfig), @(statusBarStyleConfig), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    [self setNeedsStatusBarAppearanceUpdate];
}
- (UIStatusBarStyle)statusBarStyleConfig {
    //适配与 UIViewController+ZSTopDownHUD statusBarStyle 控制的冲突；优先展示HUD设置的style
    #pragma clang diagnostic push
           #pragma clang diagnostic ignored"-Wundeclared-selector"
    NSNumber *style = nil;
    if ([self respondsToSelector:@selector(statusBarStyleForTopDownHUD)]) {
        style = objc_getAssociatedObject(self, @selector(statusBarStyleForTopDownHUD));
    }
    #pragma clang diagnostic pop
    if (style) {
        return style.integerValue;
    }
    NSNumber *style2 = objc_getAssociatedObject(self, _cmd);
    if (style2) {
        return style2.integerValue;
    }
    return UIStatusBarStyleLightContent;
}

@end
